package pl.us.ij.plugins.segmentation.infrastructure;

import ij.ImagePlus;
import ij.measure.ResultsTable;
import ij.process.FloatProcessor;
import pl.us.ij.plugins.segmentation.infrastructure.exceptions.BreakCommandException;
import pl.us.ij.plugins.segmentation.localization.Localization;

/**
 * Created by IntelliJ IDEA.
 * User: Przemek
 * Date: 2010-05-20
 * Time: 11:08:36
 * To change this template use File | Settings | File Templates.
 */
public class ShowPixelValuesCommand extends Command {
    String resultsTitle;

    @Override
    protected void processImage(FloatProcessor fp) throws BreakCommandException {
        ResultsTable rt = new ResultsTable();

        for ( int row = 0; row < 5; row++ ) {
            rt.incrementCounter();
            for ( int col = 0; col < 5; col++ ) {
                rt.addValue("" + (col + 1), fp.getPixelValue(col, row));
            }
        }

        rt.show(String.format(Localization.getString("ShowPixelValuesCommand.title"), createOutImageTitle()));
    }

    @Override
    protected ImagePlus prepareOutImage(ImagePlus inImage) {
        resultsTitle = createOutImageTitle(inImage);
        return inImage;
    }

    @Override
    protected boolean finalizeOutImage(ImagePlus outImp) {
        return false;
    }

    @Override
    protected String composeOutImageTitle(String shortTitle, String extension) {
        return String.format("%s.%s", shortTitle, extension);
    }
}
